// 用于生成和解析token
const jwt = require('jsonwebtoken');
const signkey = 'mes_qdhd_mobile_xhykjyxgs';
exports.setToken = function(username, userid) {
  return new Promise((resolve, reject) => {
    const token = jwt.sign({
      name: username,
      _id: userid,
    }, signkey, { expiresIn: '7d'});
    resolve(token);
  });
}

exports.verToken = function(token) {
  return new Promise((resolve, reject) => {
    const info = jwt.verify(token.split(' ')[1], signkey);
    resolve(info);
  });
}
